/*
 * Copyright 2009 Yannick Stucki (yannickstucki.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.yannickstucki.android.musicqueue;

import android.util.Log;

/**
 * A simple and convenient wrapper for {@link Log}. It allows the output of any
 * primitive data type and supports a main and a debug channel for logging.
 * 
 * @author Yannick Stucki (yannickstucki@gmail.com)
 * 
 */
public final class Logger {

  /**
   * In this channel are the permanent (non production) logs.
   */
  private static final String MAIN_CHANNEL = "MUSIC";

  /**
   * In this channel are the temporary debug logs.
   */
  private static final String DEBUG_CHANNEL = "MUSIC_DEBUG";

  /**
   * Utility class should not have a public of default constructor.
   */
  private Logger() {
  }

  /**
   * Outputs an exception to the main channel.
   */
  public static void out(Exception e) {
    StackTraceElement[] ste = e.getStackTrace();
    for (int i = 0; i < ste.length; i++) {
      Log.e(MAIN_CHANNEL, ste[i].toString());
    }
    Log.e(MAIN_CHANNEL, e.getMessage());
  }

  /**
   * Outputs a string to the main channel.
   */
  public static void out(String message) {
    Log.i(MAIN_CHANNEL, message);
  }

  /**
   * Outputs an int for the main channel.
   */
  public static void out(int message) {
    Log.i(MAIN_CHANNEL, "" + message);
  }

  /**
   * outputs a double to the main channel.
   */
  public static void out(double message) {
    Log.i(MAIN_CHANNEL, "" + message);
  }

  /**
   * Outputs a string to the main channel as an error (red).
   */
  public static void error(String message) {
    Log.e(MAIN_CHANNEL, message);
  }

  /**
   * Outputs an error to the debug channel.
   */
  public static void debug(Exception e) {
    StackTraceElement[] ste = e.getStackTrace();
    for (int i = 0; i < ste.length; i++) {
      Log.e(DEBUG_CHANNEL, ste[i].toString());
    }
    Log.e(DEBUG_CHANNEL, e.getMessage());
    Log.e(DEBUG_CHANNEL, e.toString());
  }

  /**
   * Outputs a string to the debug channel.
   */
  static void debug(String message) {
    Log.i(DEBUG_CHANNEL, message);
  }

  /**
   * outputs an int to the debug channel.
   */
  static void debug(int message) {
    Log.i(DEBUG_CHANNEL, "" + message);
  }

  /**
   * outputs a double to the debug channel.
   */
  static void debug(double message) {
    Log.i(DEBUG_CHANNEL, "" + message);
  }
}
